package com.lsl.menglushishang.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lsl.menglushishang.dao.CollectDao;
import com.lsl.menglushishang.dao.MainDataDao;
import com.lsl.menglushishang.dao.ProductDescDao;
import com.lsl.menglushishang.dao.ProductListDao;
import com.lsl.menglushishang.net.ImageAnsyLoader;
import com.lsl.menglushishang.net.ImageAnsyLoader.ImageAnsyLoadListener;
import com.lsl.menglushishang.po.Product;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;

public class ProductManager {
	
	private Context context;
	private SharedPreferences sp;
	private ImageAnsyLoader imageAnsyLoader;
	private ProductListDao productListDao;
	private MainDataDao mainDataDao;
	private ProductDescDao productDescDao;
	private CollectDao collectDao;
	
	public ProductManager(Context context){
		this.context = context;
		imageAnsyLoader = new ImageAnsyLoader(context);
		productListDao= new ProductListDao(context);
		mainDataDao = new MainDataDao(context);
		productDescDao = new ProductDescDao(context);
		collectDao = new CollectDao(context);
	}
	
	public ProductManager(Context context,SharedPreferences sp){
		this.context = context;
		this.sp = sp;
		imageAnsyLoader = new ImageAnsyLoader(context);
		productListDao= new ProductListDao(context,sp);
		mainDataDao = new MainDataDao(context, sp);
		productDescDao = new ProductDescDao(context, sp);
		collectDao = new CollectDao(context);
	}
	
	public Bitmap ansyLoadImage(String imageURL , ImageAnsyLoadListener listener){
		return imageAnsyLoader.loadImage(imageURL, listener);
	}
	
	
	public List<Product> getProductList(String firstCategory,String secondCategory,String thirdCategory,String sort)throws Exception {
		return productListDao.getProductList(firstCategory,secondCategory,thirdCategory,sort);
	}
	
	public List getMainPageList(final int flag) throws Exception{
		return mainDataDao.getMainPageList(flag);
	}
	
	
	public Map getDescImageList(Product p) throws Exception{
		return productDescDao.getDescImageList(p);
	}
	
	public List<Product> getCollectProductList() throws Exception{
		return collectDao.getCollectProductList();
	}
	
	public void insertCollect(Product p) throws Exception {
		collectDao.insertCollect(p);
	}
	
	public void deleteCollectById(int id) throws Exception {
		collectDao.deleteCollectById(id);
	}
	
}
